﻿//////////////////////////////////////此为批量上传图片JS代码/////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//增加上传图片框
	var TfileUploadNum=1;//记录图片选择框个数
	var Tnum = 1; //ajax上传图片时索引
	function TDeleteFileUpload() {
	    if (TfileUploadNum > 1) {
	        $("#uploadImg" + TfileUploadNum).parent().parent().remove();
	        TfileUploadNum -= 1;
	    }
	}
	function TAddFileUpload()
	{
		var idnum = TfileUploadNum+1;
		var str="<tr><td class='tdClass'>图片"+idnum+":</td>";
		str += "<td class='tdClass'><input name='' size='30' id='uploadImg" + idnum + "' type='file' />&nbsp;<span id='uploadImgState" + idnum + "'>";
		//str += "<input type='button' value='确定上传' onClick=\"SubmitUploadImageFile('uploadImg"+idnum+"')\" />";
		str += "</span></td></tr>";
		$("#imgTable").append(str);
		TfileUploadNum += 1;
		//$("#uploadImg"+idnum+"").hide();
	}
	//提交按钮事件，批量提交
	function TSubmitUploadImageFile()
	{
		//$("SubUpload").disabled=true;
		//$("CancelUpload").disabled=true;
	    //$("AddUpload").disabled=true;
	    //setTimeout("TajaxFileUpload()", 1000);
	    TajaxFileUpload();
	    
	}
	
	function TajaxFileUpload()
	{
		while(Tnum<TfileUploadNum+1)
		{
			//准备提交处理
		    //$("#uploadImgState" + Tnum).html("<img src='../../App_Themes/Default_1/Images/load.gif' width='20' height='20'/>");
		    var a = $("#uploadImg" + Tnum).val();
		    var b = $("#pcategory").text();
		    var orderid= $("#Label_ID").text();
		    var customid = $("#CustomId").text();

		   
             //20121022 手工修改。在IE8下，获取文件路径时，显示为fakepath的问题解决方案。
		    var file_upl = document.getElementById('uploadImg'+Tnum);
		    file_upl.select();

		    var realpath = document.selection.createRange().text;

		    ////20121022 手工修改。在IE8下，获取文件路径时，显示为fakepath的问题解决方案。
		    $.ajax
			({
			    type: "POST",
			    url: "../../ashx/SavePicture.ashx",
			    data: { upfile: realpath, orderid: $("#Label_ID").text(), customid: $("#CustomId").text() },
			    success: function(data, status) {
			        //alert(data);
			        var stringArray = data.split("|");

			        if (stringArray[0] == "1") {
			            //stringArray[0]    成功状态(1为成功，0为失败)
			            //stringArray[1]    上传成功的文件名
			            //stringArray[2]    消息提示
			            //$("#uploadImgState" + Tnum).html("<img src='../../App_Themes/Default_1/Images/ok.gif' width='20' height='20'/>"); //+stringArray[1]+"|"+stringArray[2]);
			            var myDate = new Date();
			            var str = $("#TextBox_Message").html();
			            var sess = $("#Label1_UserID").html();
			            var url = stringArray[1];
			            var imgstr = "<a href='" + url + "' id='thickbox'><img src='" + url + "' alt='Single Image'width='40px' height='60px'/></a>";
			            var temp = sess + " " + myDate.toLocaleString().replace("年", "/").replace("月", "/").replace("日", "/") + "</br>" + imgstr + "</br>";
			            newstr = str + temp;
			            $("#TextBox_Message").html(newstr);
			            $("a").fancybox();
			            $("#TextBox_New").val("");
			            $("#FormDiv").hide();
			        }
			        else {
			            //上传出错
			            //$("#uploadImgState" + Tnum).html("<img src='../../App_Themes/Default_1/Images/error.gif' width='20' height='20'/>" + stringArray[2]); //+stringArray[2]+"");
			            alert("上传出错");
			            $("#FormDiv").hide();
			        }
			        
			        //setTimeout("TSubmitUploadImageFile()", 0);
			       
			    }
			});
			Tnum++;
			 
		}
		while (TfileUploadNum != 1) {
		    TDeleteFileUpload();
		}
		while (TfileUploadNum > 0) {
		    $("#uploadImg" + TfileUploadNum).parent().parent().remove();
		    TfileUploadNum -= 1;
		}
		TAddFileUpload()
		Tnum = 1;
		TfileUploadNum = 1;
	}